###########################################
#SIENNA NORDQUIST##########################
#UNIVERSITA' BOCCONI#######################
#DAVID RK ADLER############################
#OXFORD UNIVERSITY#########################
#ALEXANDROS KENTIKELENIS###################
#FINAL DRAFT: JULY 15, 2024################
###########################################
#Load packages
library(naniar)
library(dplyr)
library(tidyr)
library(ggplot2)
library(questionr)
library(Hmisc)
library(gdata)
library(weights)
library(reshape2)
library(forcats)
library(texreg)
library(plyr)
library(ggpubr)
library(coefplot)
###Figure 1
Globalization_edited <- Globalization
#make proper levels
Globalization_edited$inst_view_changed_UN <- as.factor(Globalization_edited$inst_view_changed_UN)
levels(Globalization_edited$inst_view_changed_UN) <- c("More Critical","More Supportive", "No Change")
Globalization_edited$inst_view_changed_WHO <- as.factor(Globalization_edited$inst_view_changed_WHO)
levels(Globalization_edited$inst_view_changed_WHO) <- c("More Critical","More Supportive", "No Change")
Globalization_edited$inst_view_changed_USMCA <- as.factor(Globalization_edited$inst_view_changed_USMCA)
levels(Globalization_edited$inst_view_changed_USMCA) <- c("More Critical","More Supportive", "No Change")
#Save data with UN weighted proportions
#Make weighted proportion table for data first
prop.wtable<-wpct(Globalization_edited$inst_view_changed_UN,weight=Globalization_edited$weight)
prop.wtable<-as.data.frame(prop.wtable)
names(prop.wtable)[1]<- "United Nations"
prop.wtable$Var1 <-  c("More Critical","More Supportive", "No Change")
prop.wtable2<-wpct(Globalization_edited$inst_view_changed_WHO,weight=Globalization_edited$weight)
prop.wtable2<-as.data.frame(prop.wtable2)
names(prop.wtable2)[1]<- "WHO"
prop.wtable2$Var1 <-  c("More Critical","More Supportive", "No Change")
prop.wtable3<-wpct(Globalization_edited$inst_view_changed_USMCA,weight=Globalization_edited$weight)
prop.wtable3<-as.data.frame(prop.wtable3)
names(prop.wtable3)[1]<- "USMCA/NAFTA"
prop.wtable3$Var1 <-  c("More Critical","More Supportive", "No Change")
#Now merge tables and make figure in ggplot
prop.wtable4 <- merge(prop.wtable, prop.wtable2, by=c("Var1"),all.x=TRUE)
prop.wtable4<-merge(prop.wtable4,prop.wtable3, by=c("Var1"),all.x=TRUE)
melted<-melt(prop.wtable4, id="Var1")
#Relevel so No Change group is in the center
melted<-melted %>% mutate(Var1=fct_relevel(Var1,"More Critical","No Change","More Supportive"))
print(ggplot(melted,aes(x=Var1,y=value,fill=variable)) + 
        geom_bar(stat="identity",position = "dodge")) + 
        ylim(0,0.55) + xlab("Change in Opinion") + ylab("Proportion") + scale_fill_brewer(palette ="Set2") + labs(fill = "") + theme(axis.text.x = element_text(size = 12)) + guides(color = guide_legend(override.aes = list(size = 0.5))) + theme(legend.text = element_text(size = 12)) + theme(axis.title.x = element_text(vjust=1)) + theme(plot.title = element_text(size=12)) + theme(axis.title.y = element_text(size=12)) + theme(axis.text.y = element_text(size = 12)) + theme(plot.title = element_text(hjust = 0.5))
###Figure 2
#Make data frames first of weighted proportion of respondents who favor each option on int'l institutions
prop.wtable<-wpct(Globalization_edited$un_membership,weight=Globalization_edited$weight)
prop.wtable<-as.data.frame(prop.wtable)
names(prop.wtable)[1]<- "United Nations"
prop.wtable$Var1 <-  c("Leave & Build New IO","Leave & End Mission", "Leave & Pursue Mission Alone","Stay & Keep Status Quo","Stay & Reform")
prop.wtable2<-wpct(Globalization_edited$who_membership,weight=Globalization_edited$weight)
prop.wtable2<-as.data.frame(prop.wtable2)
names(prop.wtable2)[1]<- "WHO"
prop.wtable2$Var1 <-  c("Leave & Build New IO","Leave & End Mission", "Leave & Pursue Mission Alone","Stay & Keep Status Quo","Stay & Reform")
prop.wtable3<-wpct(Globalization_edited$usmca_membership,weight=Globalization_edited$weight)
prop.wtable3<-as.data.frame(prop.wtable3)
names(prop.wtable3)[1]<- "USMCA/NAFTA"
prop.wtable3$Var1 <-  c("Leave & Build New IO","Leave & End Mission", "Leave & Pursue Mission Alone","Stay & Keep Status Quo","Stay & Reform")
#Merge proportion tables
prop.wtable4 <- merge(prop.wtable, prop.wtable2, by=c("Var1"),all.x=TRUE)
prop.wtable4<-merge(prop.wtable4,prop.wtable3, by=c("Var1"),all.x=TRUE)
melted<-melt(prop.wtable4, id="Var1")
#Reorder levels
melted$Var1 <- factor(melted$Var1,levels = c("Leave & End Mission","Leave & Pursue Mission Alone","Leave & Build New IO","Stay & Reform","Stay & Keep Status Quo"))
#Print figure
print(ggplot(melted,aes(x=Var1,y=value,fill=variable)) + 
        geom_bar(stat="identity",position = "dodge")) + 
        ylim(0,0.5) + xlab("Opinion of Desired US Action on International Organizations") + ylab("Proportion") + scale_fill_brewer(palette ="Set2") + labs(fill = "") + theme(axis.text.x = element_text(size = 12)) + guides(color = guide_legend(override.aes = list(size = 0.5))) + theme(legend.text = element_text(size = 12)) + theme(axis.title.x = element_text(vjust=1)) + theme(plot.title = element_text(size=12)) + theme(axis.title.y = element_text(size=12)) + theme(axis.text.y = element_text(size = 12)) + theme(plot.title = element_text(hjust = 0.5))
#Determine number of NAs
summary(Globalization_edited$inst_view_changed_UN) #144 NAs for UN
summary(Globalization_edited$inst_view_changed_WHO) #119 NAs for UN
summary(Globalization_edited$inst_view_changed_USMCA) #242 NAs for UN
###Figure 3
#First make data frames to save proportion data by type of cooperation
#Reframe cooperation as engagement to better reflect the survey wording
prop.wtable<-wpct(Globalization$attention_on_coop_merged,weight=Globalization$weight)
prop.wtable<-as.data.frame(prop.wtable)
names(prop.wtable)[1]<- "Engagement Overall"
prop.wtable$Var1 <-  c("Current level is about right","Far less attention", "Far more attention","Slightly less attention","Slightly more attention")
prop.wtable$Var1 <- factor(prop.wtable$Var1,                                    # Change ordering manually
                           levels =  c("Far less attention", "Slightly less attention", "Current level is about right", "Slightly more attention", "Far more attention"))
prop.wtable2<-wpct(Globalization$attention_on_coop_environment,weight=Globalization$weight)
prop.wtable2<-as.data.frame(prop.wtable2)
names(prop.wtable2)[1]<- "Environmental Issues"
prop.wtable2$Var1 <-  c("Current level is about right","Far less attention", "Far more attention","Slightly less attention","Slightly more attention")
prop.wtable2$Var1 <- factor(prop.wtable$Var1,                                    # Change ordering manually
                            levels =  c("Far less attention", "Slightly less attention", "Current level is about right", "Slightly more attention", "Far more attention"))
prop.wtable3<-wpct(Globalization$attention_on_coop_infectious_diseases,weight=Globalization$weight)
prop.wtable3<-as.data.frame(prop.wtable3)
names(prop.wtable3)[1]<- "Infectious Diseases"
prop.wtable3$Var1 <-  c("Current level is about right","Far less attention", "Far more attention","Slightly less attention","Slightly more attention")
prop.wtable3$Var1 <- factor(prop.wtable3$Var1,                                    # Change ordering manually
                            levels =  c("Far less attention", "Slightly less attention", "Current level is about right", "Slightly more attention", "Far more attention"))
prop.wtable4<-wpct(Globalization$attention_on_coop_living_standards,weight=Globalization$weight)
prop.wtable4<-as.data.frame(prop.wtable4)
names(prop.wtable4)[1]<- "Living Standards"
prop.wtable4$Var1 <-  c("Current level is about right","Far less attention", "Far more attention","Slightly less attention","Slightly more attention")
prop.wtable4$Var1 <- factor(prop.wtable$Var1,                                    # Change ordering manually
                            levels =  c("Far less attention", "Slightly less attention", "Current level is about right", "Slightly more attention", "Far more attention"))
#Merge proportion tables and then generate figure
prop.wtable5 <- merge(prop.wtable, prop.wtable2, by=c("Var1"),all.x=TRUE)
prop.wtable5<-merge(prop.wtable5,prop.wtable3, by=c("Var1"),all.x=TRUE)
prop.wtable5<-merge(prop.wtable5,prop.wtable4, by=c("Var1"),all.x=TRUE)
melted<-melt(prop.wtable5, id="Var1")
print(ggplot(melted,aes(x=Var1,y=value,fill=variable)) + 
        geom_bar(stat="identity",position = "dodge")) + 
        ylim(0,0.5) + xlab("Whether Respondents Want More or Less US Cooperation with Other Countries") + ylab("Proportion") + scale_fill_brewer(palette ="Set2") + labs(fill = "") + theme(axis.text.x = element_text(size = 12)) + guides(color = guide_legend(override.aes = list(size = 0.5))) + theme(legend.text = element_text(size = 12)) + theme(axis.title.x = element_text(vjust=1)) + theme(plot.title = element_text(size=12)) + theme(axis.title.y = element_text(size=12)) + theme(axis.text.y = element_text(size = 12)) + theme(plot.title = element_text(hjust = 0.5))
#averages across
(0.29+0.18+0.21+0.21)/4#22.3% average for current level is about right
(0.26+0.21+0.22+0.29)/4#24.5% average for slightly more attention
(0.16+0.41+0.46+0.35)/4#34.5% average for far more attention
0.223+0.245+0.345 #summation is 81.3%
###Figure 4
#First make weighted proportion tables by issue type
levels(Globalization_edited$issue_view_changed_environment) <- c("Less Attention","More Attention", "No Change")
Globalization_edited$issue_view_changed_environment <- as.factor(Globalization_edited$issue_view_changed_environment)
prop.wtable<-wpct(Globalization_edited$issue_view_changed_environment,weight=Globalization_edited$weight)
prop.wtable<-as.data.frame(prop.wtable)
names(prop.wtable)[1]<- "Environmental Issues"
prop.wtable$Var1 <-  c("Less Attention","More Attention", "No Change")
prop.wtable$Var1 <- factor(prop.wtable$Var1,                                    # Change ordering manually
                           levels =  c("Less Attention", "No Change", "More Attention"))
levels(Globalization_edited$issue_view_changed_infectious_diseases) <- c("Less Attention","More Attention", "No Change")
Globalization_edited$issue_view_changed_infectious_diseases <- as.factor(Globalization$issue_view_changed_infectious_diseases)
prop.wtable2<-wpct(Globalization_edited$issue_view_changed_infectious_diseases,weight=Globalization_edited$weight)
prop.wtable2<-as.data.frame(prop.wtable2)
names(prop.wtable2)[1]<- "Infectious Diseases"
prop.wtable2$Var1 <-  c("Less Attention","More Attention", "No Change")
prop.wtable2$Var1 <- factor(prop.wtable2$Var1,                                    # Change ordering manually
                            levels =  c("Less Attention", "No Change", "More Attention"))
levels(Globalization_edited$issue_view_changed_living_standards) <- c("Less Attention","More Attention", "No Change")
Globalization_edited$issue_view_changed_living_standards <- as.factor(Globalization_edited$issue_view_changed_living_standards)
prop.wtable3<-wpct(Globalization$issue_view_changed_living_standards,weight=Globalization$weight)
prop.wtable3<-as.data.frame(prop.wtable3)
names(prop.wtable3)[1]<- "Living Standards"
prop.wtable3$Var1 <-  c("Less Attention","More Attention", "No Change")
prop.wtable3$Var1 <- factor(prop.wtable3$Var1,                                    # Change ordering manually
                            levels =  c("Less Attention", "No Change", "More Attention"))
#Merge weighted proportion tables, Make and print figure
prop.wtable4 <- merge(prop.wtable, prop.wtable2, by=c("Var1"),all.x=TRUE)
prop.wtable4<-merge(prop.wtable4,prop.wtable3, by=c("Var1"),all.x=TRUE)
melted<-melt(prop.wtable4, id="Var1")
print(ggplot(melted,aes(x=Var1,y=value,fill=variable)) + 
        geom_bar(stat="identity",position = "dodge")) + 
        ylim(0,0.75) + xlab("Whether Respondents Changed Their Mind on US Cooperation") + ylab("Proportion") + scale_fill_brewer(palette ="Set2") + labs(fill = "") + theme(axis.text.x = element_text(size = 12)) + guides(color = guide_legend(override.aes = list(size = 0.5))) + theme(legend.text = element_text(size = 12)) + theme(axis.title.x = element_text(vjust=1)) + theme(plot.title = element_text(size=12)) + theme(axis.title.y = element_text(size=12)) + theme(axis.text.y = element_text(size = 12)) + theme(plot.title = element_text(hjust = 0.5))
###Online Appendix 3 - Table 1
lm1 <- lm(inst_view_changed_UN_negative ~ white + above_45 + college + urban + suburban + republican + income_high + male, data=Globalization_edited, weights = weight)
summary(lm1)
lm2 <- lm(inst_view_changed_WHO_negative ~ white + above_45 + college + urban + suburban + republican + income_high + male, data=Globalization_edited, weights = weight)
summary(lm2)
lm3 <- lm(inst_view_changed_USMCA_negative ~ white + above_45 + college + urban + suburban + republican + income_high + male, data=Globalization_edited, weights = weight)
summary(lm3)
htmlreg(l=list(lm1, lm2, lm3), file="Inst view changed negative.html")
